// export function generateCoverURL (url, cropRule) {
//   if (!url || !cropRule) return url

//   const parsedUrl = new URL(url)

//   if (parsedUrl.pathname.endsWith('.webp')) {
//     return url
//   }

//   const isQuery = parsedUrl.search.length > 0

//   const separator = isQuery ? '&' : '?'

//   return url + separator + cropRule
// }


const CDN = 'cdn.isscloud.site';
 export function generateCoverURL(cloudId, options) {

   if (!cloudId) return '';
    const {h , w} = options || {};
   // 如果已经是http/https链接，直接返回
   if (cloudId.startsWith('http://') || cloudId.startsWith('https://')) {
	
     return cloudId+((w) ? `?imageView2/0/w/${w}`:'');
   }
   
   // 处理七牛云格式 qiniu://path/to/file
   if (cloudId.startsWith('qiniu://')) {
	
     const path = cloudId.replace('qiniu://', '');
	
	 if(w) {
		 return  `https://${CDN}/${path}?imageView2/0/w/${w}`;
	 }
     return `https://${CDN}/${path}`;
   }
   
   // 处理阿里云格式 cloud://env-id/path/to/file
   if (cloudId.startsWith('cloud://')) {
	   	    
     const matches = cloudId.match(/^cloud:\/\/([^/]+)\/(.+)$/);
     if (matches && matches.length >= 3) {
       const env = matches[1]; // 环境ID
       const filePath = matches[2]; // 文件路径
	   if(w) {
	   		 return  `https://${env}.normal.cloudstatic.cn/${filePath}?imageView2/0/w/${w}`;
	   }
       return `https://${env}.normal.cloudstatic.cn/${filePath}`;
     }
   }
   
   console.warn('Invalid cloud storage ID:', cloudId);
   return cloudId; // 返回原始值，避免报错
 }
